Skip to content

Replace catching StackOverflowError with fuel#25937

Draft
SolalPirelli wants to merge 3 commits into
scala:mainfrom
dotty-staging:solal/fuel
Draft

Replace catching StackOverflowError with fuel#25937
SolalPirelli wants to merge 3 commits into
scala:mainfrom
dotty-staging:solal/fuel

Conversation

@SolalPirelli
Copy link
Copy Markdown
Contributor

@SolalPirelli SolalPirelli commented Apr 27, 2026

Part of #25799

How much have you relied on LLM-based tools in this contribution?

Not at all

How was the solution tested?

Covered by existing tests (this is a refactoring)

T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoids a stack overflow; this test was introduced purely as a stress test in d3ac612 and the other elements of it were already reduced in 0ee31f4 so I think removing this line is fine

@SolalPirelli SolalPirelli force-pushed the solal/fuel branch 2 times, most recently from 958aabd to 1e2b230 Compare April 29, 2026 11:17
@SolalPirelli SolalPirelli changed the title no-review: Fuel Replace catching StackOverflowError with fuel Apr 29, 2026
Comment thread compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala Outdated
Comment thread compiler/src/dotty/tools/dotc/core/SymDenotations.scala
@SolalPirelli SolalPirelli force-pushed the solal/fuel branch 3 times, most recently from e3ff246 to 44aa990 Compare May 18, 2026 13:00
@SolalPirelli SolalPirelli requested review from mbovel and sjrd May 18, 2026 14:23
@mbovel

This comment was marked as outdated.

@mbovel
Copy link
Copy Markdown
Member

mbovel commented May 20, 2026

Benchmarks completed. Overview.

Comment thread compiler/src/dotty/tools/dotc/core/Contexts.scala Outdated

/** Ensures recursive operations obey the fuel limit, and throws user-friendly errors when they do not. */
inline final def handleRecursive[T](name: String, details: => String, weight: Int = 1)(inline block: T): T =
val op = RecursiveOperation(name, details, weight)
Copy link
Copy Markdown
Member

@bishabosha bishabosha May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also isnt this in the past this metadata only needed for the "outermost" operation, so perhaps another optimisation (rather than capturing a whole trace even in happy path)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or tune the level of tracing captured via settings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the entire trace if something goes wrong, so we can show a message with the most frequent operations etc

but yeah the problem is fundamentally since we can't catch SOs we have to store info even in the happy path; I'll look at ways to lower the impact of this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that you actually still use the stack to recurse, cant you only construct the metadata when you throw the exception and then catch the exception from each outer layer to add its trace in and rethrow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'm a little allergic to using exceptions for control flow, and it might negate the perf gains of not building the metadata, but we'll see if this latest benchmark run isn't good enough

@mbovel
Copy link
Copy Markdown
Member

mbovel commented May 20, 2026

Benchmarks started. Workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants